

package com.loong.loong.hik.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.loong.loong.common.core.util.R;
import com.loong.loong.common.excel.annotation.ResponseExcel;
import com.loong.loong.common.log.annotation.SysLog;
import com.loong.loong.hik.entity.WatchPeople;
import com.loong.loong.hik.service.WatchPeopleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 巡更人员
 *
 * @author jinyiang
 * @date 2023-03-30 14:35:09
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/watchpeople" )
@Api(value = "watchpeople", tags = "巡更人员管理")
public class WatchPeopleController {

    private final  WatchPeopleService watchPeopleService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param watchPeople 巡更人员
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('hik_watchpeople_view')" )
    public R getWatchPeoplePage(Page page, WatchPeople watchPeople) {
        return R.ok(watchPeopleService.page(page, Wrappers.query(watchPeople).lambda()
		.like(StringUtils.isNotEmpty(watchPeople.getWatchMan()),WatchPeople::getWatchMan,watchPeople.getWatchMan())
				.between(StringUtils.isNotEmpty
						(watchPeople.getStartTime())&&StringUtils.isNotEmpty(watchPeople.getEndTime()),WatchPeople::getCreateTime,watchPeople.getStartTime(),watchPeople.getEndTime())));
    }
    /**
     * 通过id查询巡更人员
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('hik_watchpeople_view')" )
    public R getById(@PathVariable("id" ) Integer id) {
        return R.ok(watchPeopleService.getById(id));
    }

    /**
     * 新增巡更人员
     * @param watchPeople 巡更人员
     * @return R
     */
    @ApiOperation(value = "新增巡更人员", notes = "新增巡更人员")
    @SysLog("新增巡更人员" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('hik_watchpeople_add')" )
    public R save(@RequestBody WatchPeople watchPeople) {
		return R.ok(watchPeopleService.save(watchPeople));
    }

    /**
     * 修改巡更人员
     * @param watchPeople 巡更人员
     * @return R
     */
    @ApiOperation(value = "修改巡更人员", notes = "修改巡更人员")
    @SysLog("修改巡更人员" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('hik_watchpeople_edit')" )
    public R updateById(@RequestBody WatchPeople watchPeople) {
        return R.ok(watchPeopleService.updateById(watchPeople));
    }

    /**
     * 通过id删除巡更人员
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除巡更人员", notes = "通过id删除巡更人员")
    @SysLog("通过id删除巡更人员" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('hik_watchpeople_del')" )
    public R removeById(@PathVariable Integer id) {
        return R.ok(watchPeopleService.removeById(id));
    }


    /**
     * 导出excel 表格
     * @param watchPeople 查询条件
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('hik_watchpeople_export')" )
    public List<WatchPeople> export(WatchPeople watchPeople) {
        return watchPeopleService.list(Wrappers.query(watchPeople));
    }
}
